﻿using Common.Unity.Extensions.Configuration;
using Common.Unity.Extensions.PropertyMapping.Testing.Objects;
using Microsoft.Practices.Unity;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Common.Unity.Extensions.PropertyMapping.Testing
{
	/// <summary>
	/// Summary description for PropertyMappingCreatorPolicyTests
	/// </summary>
	[TestClass]
	public class PropertyMappingCreatorPolicyTests
	{
		[TestMethod]
		public void VerifyPolicyWorks()
		{
			var instance = new TargetObject
			               	{
			               		TargetProperty =
			               			new TargetObjectItem { Name = "Hello World" }
			               	};
			var container =
				new UnityContainer().AddNewExtension<CommonExtension>().RegisterInstance( instance );
			container.RegisterType<TargetObjectItem>( new PolicyInjection( typeof(IObjectCreationPolicy),
			                                                               new PropertyMappingCreatorPolicy
			                                                               	{
			                                                               		Expression = "TargetProperty",
			                                                               		TargetBuildType = typeof(TargetObject)
			                                                               	} ) );
			var target = container.Resolve<TargetObjectItem>();
			Assert.IsNotNull( target );
			Assert.AreEqual( "Hello World", target.Name );
			Assert.AreSame( instance.TargetProperty, target );
		}
	}
}
